﻿Imports System.Data

Partial Class WebForm_CommonControl_VolunteerQueryControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Me.LoadOnStartUp = True Then
                Me.InitData()
            End If
        End If
    End Sub



    Private Sub BindDDLVOrganizationID()
   

        Me.ddlVOrganizationID.DataTextField = "VOrganizationName"
        Me.ddlVOrganizationID.DataValueField = "VOrganizationID"
        Me.ddlVOrganizationID.DataSource = MyObj.GetVOrganizationData(ddlOrganizationID.SelectedValue)
        Me.ddlVOrganizationID.DataBind()

        'If Me.ddlVOrganizationID.Items.Count > 1 Then
        '    Me.ddlVOrganizationID.Items.Insert(0, MyObj.GetDDLSelectAllItem())
        'End If

        '初始值為隱藏
        Me.phVOrganizationID.Visible = True
    End Sub
    Public Sub InitData()

        '鄉鎮市

        'If Me.Admin = True Then
        '    ddlRegion.DataSource = MyObj.GetTownData()
        'Else
        '    ddlRegion.DataSource = clsAuth.GetTownData()
        'End If

        'ddlRegion.DataBind()

        ''村里

        'If Me.Admin = True Then
        '    ddlRegion2.DataSource = clsAuth.GetVillageData(ddlRegion.SelectedValue)
        'Else
        '    ddlRegion2.DataSource = MyObj.GetVillageData(ddlRegion.SelectedValue)
        'End If

        'ddlRegion2.DataBind()

        txtVolunteerId.Text = String.Empty
        txtVolunteerName.Text = String.Empty
        txtTEL.Text = String.Empty

        '發展協會志工隊

        'If Me.Admin = True Then
        '    ddlVOrganizationID.DataSource = MyObj.GetVOrganization()
        'Else
        '    ddlVOrganizationID.DataSource = clsAuth.GetVOrganization()
        'End If

        'ddlVOrganizationID.DataBind()

        '運用單位
        'If Me.Admin = True Then
        '    ddlOrganizationID.DataSource = MyObj.GetDDLDirectOrganizationData()
        'Else

        '    ddlOrganizationID.DataSource = MyObj.GetOrganizationData(IsVolunteerLeader)
        'End If

        'ddlOrganizationID.DataBind()
        'Dim dat As New clsData
        'If clsAuth.GetUser().VolunteerLeader = True Then

        '    Dim sql As New MyStringBuilder

        '    sql.AppendFormat("select distinct o.OrganizationName, o.DirectUOrganizationID as UOrganizationID from VOrganizationView o ")
        '    sql.AppendFormat("inner join VolunteerView v on o.UOrganizationID = v.UOrganizationID ")
        '    sql.AppendFormat("inner join OtherOrganizationMapping om on v.UOrganizationID=om.UOrganizationID ")
        '    sql.AppendFormat("where om.UserID = '{0}' ", clsAuth.GetUserID())
        '    sql.AppendFormat("order by o.OrganizationName ") 'Add by Shihyu 2010/10/12

        '    ddlOrganizationID.DataSource = dat.GetData(sql)
        'Else
        '    Dim sql As New MyOrganizationDataFilter

        '    sql.AppendFormat("select o.OrganizationName,o.UOrganizationID from OrganizationView o ")
        '    sql.AppendFormat("where OrganizationType <> 'V' and Active='Y' ")
        '    sql.AppendFormat("order by OrganizationName ") 'Add by Shihyu 2010/10/12
        '    ddlOrganizationID.DataSource = dat.GetData(sql)
        '    ' Me.phVOrganizationID.Visible = False
        'End If
        'ddlOrganizationID.DataBind()
        If Me.Admin = True Then
            ddlOrganizationID.DataSource = MyObj.GetDDLDirectOrganizationData()
        Else

            ddlOrganizationID.DataSource = MyObj.GetOrganizationData(IsVolunteerLeader)
        End If
        ddlOrganizationID.DataBind()
    End Sub
    Protected Sub ddlOrganizationID_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOrganizationID.DataBound
        If Me.ddlOrganizationID.Items.Count > 1 Then
            ddlOrganizationID.Items.Insert(0, MyObj.GetDDLSelectAllItem())
        Else
            Me.BindDDLVOrganizationID()
        End If
    End Sub

   
    Protected Sub ddlOrganizationID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOrganizationID.SelectedIndexChanged
        If Me.ddlOrganizationID.SelectedValue <> "" Then
            Me.BindDDLVOrganizationID()
            ' Me.ObjectDataSource1.SelectParameters("DirectUOrganizationID").DefaultValue = Me.ddlOrganizationID.SelectedValue
        Else
            ' Me.ddlVOrganizationID.DataBind()
            Me.phVOrganizationID.Visible = False
            ddlVOrganizationID.Items.Clear()
        End If

        Show_mpSearch()
    End Sub
    'Protected Sub ddlRegion_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRegion.DataBound
    '    If ddlRegion.Items.Count = 0 Then
    '        Me.trRegion.Visible = False
    '    ElseIf ddlRegion.Items.Count > 1 Then
    '        ddlRegion.Items.Insert(0, MyObj.GetDDLSelectAllItem())
    '    End If

    '    If Not ddlRegion.Visible Then
    '        ddlRegion.Items.Insert(0, MyObj.GetDDLSelectAllItem())
    '    End If

    'End Sub

    'Protected Sub ddlRegion2_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRegion2.DataBound
    '    If ddlRegion2.Items.Count = 0 Then
    '        Me.lblRegion2.Visible = False
    '        Me.ddlRegion2.Visible = False
    '    Else
    '        Me.lblRegion2.Visible = True
    '        Me.ddlRegion2.Visible = True
    '    End If

    '    ddlRegion2.Items.Insert(0, MyObj.GetDDLSelectAllItem())

    'End Sub

    Protected Sub ddlVOrganizationID_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlVOrganizationID.DataBound
        'If ddlVOrganizationID.Items.Count = 0 Then
        'Me.trVOrganizationID.Visible = False
        'ElseIf ddlVOrganizationID.Items.Count > 1 Then

        If ddlVOrganizationID.Items.Count > 1 Then
            Dim li As ListItem = MyObj.GetDDLSelectAllItem()
            li.Value = "0"
            ddlVOrganizationID.Items.Insert(0, li) '因為VOrganizationID的型別是int所以請選擇的值要設0
        End If
        'End If
    End Sub

    'Protected Sub ddlRegion_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRegion.SelectedIndexChanged
    '    ddlRegion2.DataSource = clsAuth.GetVillageData(ddlRegion.SelectedValue)
    '    ddlRegion2.DataBind()

    '    Show_mpSearch()

    'End Sub

    Sub Show_mpSearch()
        If mpSearchUniqueID <> String.Empty Then
            Dim mpSearch As AjaxControlToolkit.ModalPopupExtender = Page.FindControl(mpSearchUniqueID)
            If mpSearch IsNot Nothing Then
                mpSearch.Show()
            End If
        End If
    End Sub

    Public Sub Display_EcolifeID(ByVal Display As Boolean)
        Me.PlaceHolder2.Visible = Display
    End Sub

    'Protected Sub ddlOrganizationID_Init(ByVal sender As Object, ByVal e As System.EventArgs)
    '    If Me.Admin = True Then
    '        ddlOrganizationID.DataSource = MyObj.GetDDLDirectOrganizationData()
    '    Else

    '        ddlOrganizationID.DataSource = MyObj.GetOrganizationData(IsVolunteerLeader)
    '    End If

    '    ddlOrganizationID.DataBind()
    'End Sub
End Class

Partial Class WebForm_CommonControl_VolunteerQueryControl

    'Public ReadOnly Property Region() As String
    '    Get
    '        Return IIf(txtVolunteerId.Text = String.Empty, ddlRegion.SelectedValue, String.Empty)
    '    End Get

    'End Property

    'Public ReadOnly Property RegionText() As String
    '    Get
    '        Return IIf(Me.ddlRegion.SelectedItem.Text = "----全部----", "所有", Me.ddlRegion.SelectedItem.Text)
    '    End Get
    'End Property

    'Public ReadOnly Property Region2Text() As String
    '    Get
    '        Return IIf(Me.ddlRegion2.SelectedItem.Text = "----全部----", "所有", Me.ddlRegion2.SelectedItem.Text)
    '    End Get
    'End Property

    'Public ReadOnly Property Region2() As String
    '    Get
    '        Return IIf(txtVolunteerId.Text = String.Empty, ddlRegion2.SelectedValue, String.Empty)
    '    End Get

    'End Property
    Public ReadOnly Property VOrganizationName() As String
        Get
            Return IIf(Me.ddlVOrganizationID.SelectedItem.Text = "----全部----", "所有", Me.ddlVOrganizationID.SelectedItem.Text)
        End Get
    End Property
    Public ReadOnly Property OrganizationName() As String
        Get
            Return IIf(Me.ddlOrganizationID.SelectedItem.Text = "----全部----", "所有運用單位", Me.ddlOrganizationID.SelectedItem.Text)
        End Get
    End Property
    Public ReadOnly Property VolunteerId() As String
        Get
            Return txtVolunteerId.Text.Replace("'", "''").Trim()
        End Get

    End Property

    Public ReadOnly Property EcolifeID() As String
        Get
            Return txtEcolifeID.Text.Replace("'", "''").Trim()
        End Get

    End Property

    Public ReadOnly Property VolunteerName() As String
        Get
            Return txtVolunteerName.Text.Replace("'", "''").Trim()
        End Get

    End Property

    Public ReadOnly Property VolunteerTEL() As String
        Get
            Return txtTEL.Text.Replace("'", "''").Trim()
        End Get

    End Property

    Public ReadOnly Property VOrganizationID() As String
        Get
	    If ddlVOrganizationID.SelectedValue = ""
		Return "0"
	    Else
	        Return ddlVOrganizationID.SelectedValue
	    End If
        End Get

    End Property
    Public ReadOnly Property OrganizationID() As String
        Get
            If ddlOrganizationID.SelectedValue = "" Then
                Return "0"
            Else
                Return ddlOrganizationID.SelectedValue
            End If
        End Get

    End Property
    Public Property mpSearchUniqueID() As String
        Get
            Return ViewState("MpSearchUniqueID")
        End Get
        Set(ByVal value As String)
            ViewState("MpSearchUniqueID") = value
        End Set

    End Property

    Public Property LoadOnStartUp() As Boolean
        Get
            If ViewState("LoadOnStartUp") Is Nothing Then
                Return False
            End If

            Return ViewState("LoadOnStartUp")
        End Get
        Set(ByVal value As Boolean)
            ViewState("LoadOnStartUp") = value
        End Set
    End Property

    Public Property Admin() As Boolean
        Get
            If ViewState("Admin") Is Nothing Then
                Return False
            End If

            Return ViewState("Admin")
        End Get
        Set(ByVal value As Boolean)
            ViewState("Admin") = value
        End Set
    End Property
    Public Property IsVolunteerLeader() As Boolean
        Get
            If ViewState("IsVolunteerLeader") Is Nothing Then
                Return clsAuth.GetUser.VolunteerLeader
            End If

            Return ViewState("IsVolunteerLeader")
        End Get
        Set(ByVal value As Boolean)
            ViewState("IsVolunteerLeader") = value
        End Set
    End Property
End Class